<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<div class="navbar-container ace-save-state" id="navbar-container">
	<!-- #section:basics/sidebar.mobile.toggle -->
	<button type="button" class="navbar-toggle menu-toggler pull-left" id="menu-toggler" data-target="#sidebar">
		<span class="sr-only">Toggle sidebar</span>

		<span class="icon-bar"></span>

		<span class="icon-bar"></span>

		<span class="icon-bar"></span>
	</button>

	<!-- /section:basics/sidebar.mobile.toggle -->
	<div class="navbar-header pull-left">
		<!-- #section:basics/navbar.layout.brand -->
		<a href="#" class="navbar-brand">
			<small>
				<i class="fa fa fa-fire"></i>
				<spring:message code="sys.site.title" arguments="${platformName}"/>
			</small>
		</a>

		<!-- /section:basics/navbar.layout.brand -->

		<!-- #section:basics/navbar.toggle -->

		<!-- /section:basics/navbar.toggle -->
	</div>

	<!-- #section:basics/navbar.dropdown -->
	<div class="navbar-buttons navbar-header pull-right" role="navigation">
		<ul class="nav ace-nav">
			<li class="light-blue dropdown-modal">
				<select id="loginCangku" class="dropdown-toggle" style="width: 100px;">
					<option value="">仓库</option>
				</select>
			</li>
			<!-- #section:basics/navbar.user_menu -->
			<li class="light-blue dropdown-modal">
				<a data-toggle="dropdown" href="#" class="dropdown-toggle">
					<img class="nav-user-photo" src="${fns:getUser().portrait}" alt="${fns:getUser().realname}" />
					<span class="user-info">
						<small>欢迎您,</small>
						${fns:getUser().realname}
					</span>
					<i class="ace-icon fa fa-caret-down"></i>
				</a>

				<ul class="user-menu dropdown-menu-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close">
					<li>
						<a class="J_menuItem" href="${adminPath}/sys/user/${fns:getUser().id}/avatar">
							<i class="ace-icon fa fa-user"></i>
							修改头像
						</a>
					</li>
					<li class="divider"></li>
					<li>
						<a href="#" onclick="changeStyle('inspinia')"><i class="ace-icon fa  fa-wikipedia-w"></i>INSPINIA主题</a>
					</li>
					<li class="divider"></li>
					<li>
						<a href="${adminPath}/logout">
							<i class="ace-icon fa fa-power-off"></i>
							安全退出
						</a>
					</li>
				</ul>
			</li>

			<!-- /section:basics/navbar.user_menu -->
		</ul>
	</div>

	<!-- /section:basics/navbar.dropdown -->
</div><!-- /.navbar-container -->

<html:js  name="jquery,layer"/>

<script>
	function changeStyle(theme){
		$.get('${adminPath}/theme/'+theme+'?url='+window.top.location.href,function(result){   window.location.reload();});
	}
</script>

<script type="text/javascript">
	$(document).ready(function() {
		// POST请求配送交接
		$.ajax({
			type: "POST",
			url: "${pageContext.request.contextPath}/api/user/queryLoginCangkuAndList",
			traditional: true,
			success: function (data) {
				let retData = data.data
				if (retData == undefined || retData.length < 1) {
					return
				}

				$("#loginCangku").empty();
				for(let i = 0; i < retData.length; i++) {
					$("#loginCangku").prepend("<option value ='" + retData[i].cangku + "'>" + retData[i].cangkuName + "</option>");
				}
				$("#loginCangku").val(data.extend.cangku);
			}
		});

		$("#loginCangku").change(function() {
			// POST请求配送交接
			$.ajax({
				type: "POST",
				url: "${pageContext.request.contextPath}/api/user/changeLoginCangku",
				data: {
					cangku: $('#loginCangku').val()
				},
				traditional: true,
				success: function (data) {
					if (data.ret < 0) {
						top.layer.alert(data.msg, {icon: 0, title:'提示'});
						return
					}
					let i = 0
					top.layer.alert('仓库切换完毕！', {icon: 0, title:'提示'});
					// 刷新TAB页
					$('.page-tabs-content').children("[data-id]").not(":first").each(function () {
						let that = this
						setTimeout(() => {
							let target = $('.J_iframe[data-id="' + $(that).data('id') + '"]');
							let url = target.attr('src');
							//显示loading提示
							let loading = layer.load();
							target.attr('src', url).load(function () {
								//关闭loading提示
								layer.close(loading);
							});
						}, (i++) * 100)
					});

				}
			});
		});
	});


</script>